﻿{include file="common/header" /}


<div class="page-container ">
	<form class="text-c" action="{{:url('warehouse/index')}}" id="myform" method="post"  onkeydown="if(event.keyCode==13)return false;">
		<input type="text" class="input-text" style="width:250px" placeholder="输入仓库名称" value="{{$Think.get.name}}"  name="name">
		<button type="button" onclick="getData()" class="btn btn-success" ><i class="Hui-iconfont">&#xe665;</i> 搜仓库</button>
	</form>
	<div class="cl pd-5 bg-1 bk-gray mt-20"> 
		<span class="l">
			<a href="javascript:;" onclick="add('添加仓库','{{:url('warehouse/create','',false)}}','800','500')" class="btn btn-primary radius">
				<i class="Hui-iconfont">&#xe600;</i> 添加仓库</a></span>

	</div>
	<table class="table table-border table-bordered table-bg">
		<thead>
			<tr>
				<th scope="col" colspan="9">仓库列表</th>
			</tr>
			<tr class="text-c">
				<th width="150">仓库名字</th>
				<th width="150">仓库代码</th>
				<th width="90">编号</th>
				<th width="150">仓库描述</th>
				<th width="90">状态</th>
				<th width="100">操作</th>
			</tr>
		</thead>
		<tbody id="tbody">

		</tbody>
	</table>
</div>
<div class="m-style M-box"></div>
<script id="table-lists" type="text/template">
	{{#each data}}
	<tr class="text-c">
						<td>{{name}}</td>
						<td class="td-status">{{location_code}}</td>
						<td class="td-status">{{ware_house_code}}</td>
					     <td class="td-status">{{description}}</td>
						<td class="td-status">{{status}}</td>
						<td class="td-manage">
								<a title="编辑" href="javascript:;" onclick="edit('{{id}}')" class="ml-5" style="text-decoration:none">
										<i class="Hui-iconfont">&#xe6df;</i>
									</a>
							</td>
					</tr>
	{{/each}}
</script>
<script type="text/javascript">

    getData();
    //异步获取数据
    function getData(page = 1){
        $.ajax({
            type: 'POST',
            url: '{{:url("/warehouse/index")}}?page='+page,
            data:$('#myform').serialize(),
            dataType: 'json',
            beforeSend:function(){
                layer.msg('加载中...',{time:10000});
            },
            success: function(res){
                closeLayerMsg();
                var source=$('#table-lists').html();
                var template = Handlebars.compile(source);
                $('#tbody').html(template(res.msg));
                paginate(res.msg.total,res.msg.page)
            },
            error:function(data) {}
        })
    }








    /*
        参数解释：
        title	标题
        url		请求的url
        id		需要操作的数据id
        w		弹出层宽度（缺省调默认值）
        h		弹出层高度（缺省调默认值）
    */
/*仓库-增加*/
function add(title,url,w,h){
	layer_show(title,url,w,h);
}
/*仓库-删除*/
function del(obj,id){
	layer.confirm('确认要删除吗？',function(index){
		$.ajax({
			type: 'POST',
			url: '{{:url('warehouse/delete','',false)}}',
			data:{ID:id},
			dataType: 'json',
			success: function(data){
				$(obj).parents("tr").remove();
				layer.msg('已删除!',{icon:1,time:1000});
			},
			error:function(data) {
				console.log(data.msg);
			},
		});		
	});
}



function edit(id){
    layer_show("编辑仓库",'{{:url("/warehouse/update")}}?id='+encodeURIComponent(id));
}

</script>
{include file="common/footer" /}